﻿using ComLib.ComType;
using KWindow.KPageCore;
using LogLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace IPCPages
{
    public partial class PageClickToStarting : PageControlBase
    {
        /// <summary>
        /// 连续点击激活次数统计
        /// </summary>
        private int active_click_count = 0;
        private Stopwatch sw = new Stopwatch();
        private Button buttonStart = null;
        public PageClickToStarting()
        {
            InitializeComponent();
            SetProcessBase(ProcessClickToStarting.Instance);
        }

        public override void InitCtrls()
        {
            base.InitCtrls();
            buttonStart = GetControl<Button>("buttonStart") as Button;
            SetButtonDefaultStyles(buttonStart);
        }

        //初始化窗体数据
        public override void InitData()
        {
            SD.ClearValue();
            Process.SetValue("ActionIndex", 1);
        }

        private void buttonStart_Click(object sender, EventArgs e)
        {
            Log.WriteAsync("用户点击了开始拍照按钮.");
            Process.SetValue("ApplyTo", ApplyTo.ExitAndEntry);
            Process.ToNext();
        }

        private void pictureBoxStarting_Click(object sender, EventArgs e)
        {
            Log.WriteAsync("用户点击了开始拍照图标.");
            Process.ToNext();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            if (!sw.IsRunning)
            {
                sw.Restart();
                return;
            }
            if (sw.ElapsedMilliseconds > 2000)
            {
                sw.Reset();
                active_click_count = 0;
            }
            else
            {
                active_click_count++;
            }
            if (active_click_count == 2)
            {
                sw.Reset();
                active_click_count = 0;
                Log.WriteAsync("用户打开了管理员选项");
                FormAdministrator form = new FormAdministrator();
                if (form.ShowDialog() == DialogResult.OK)
                {
                    Log.WriteAsync("即将执行管理员选项动作:" + form.SelectAction.ToString());
                    Process.OnTakeAdminAction(form.SelectAction);
                }
            }
        }
    }
}
